package com.allwees.bs.module.scm.dao;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.allwees.bs.module.scm.entity.ScmShippingOrderSku;
import com.allwees.core.common.constant.EStatus;
import com.allwees.core.dao.mybatis.dao.BaseDao;

import java.util.List;

public interface ScmShippingOrderSkuDao extends BaseDao<ScmShippingOrderSku> {

    default ScmShippingOrderSku findByOrderItemUuid(String orderItemUuid){
        return findOneByField("order_item_uuid",orderItemUuid);
    }
    default List<ScmShippingOrderSku> findByShippingOrderUuid(String shippingOrderUuid) {
        QueryWrapper<ScmShippingOrderSku> wrapper = new QueryWrapper<>();
        wrapper.eq("shipping_order_uuid",shippingOrderUuid);
        return selectList(wrapper);
    }

    default Integer findCountByShippingOrderUuid(String shippingOrderUuid) {
        return findCountByShippingOrderUuid(shippingOrderUuid,null);
    }

    default Integer findCountByShippingOrderUuid(String shippingOrderUuid, EStatus status) {

        QueryWrapper<ScmShippingOrderSku> wrapper = new QueryWrapper<>();
        wrapper.eq("shipping_order_uuid",shippingOrderUuid);
        if(status != null){
            wrapper.eq("status", status.value());
        }
        return selectCount(wrapper);
    }
}
